package pkg0;

import java.util.LinkedList;
import java.util.List;

public class Main {
	private static boolean d = true;
	
	public static void main(String[] args) {
		System.out.println("syso test !");
		int[] available = new int[]{2, 3, 0};
		int[][][] threadPool = {{{7, 5, 3}, {0, 1, 0}},
				{{3, 2, 2}, {3, 0, 2}},
				{{9, 0, 2}, {3, 0, 2}},
				{{2, 2, 2}, {2, 1, 1}}, 
				{{4, 3, 3}, {0, 0, 2}}};
		List<String> ret = djsk(available, threadPool);
		if(ret == null){
			System.out.println("failed !");
		}else{
			for(String s : ret){
				System.out.print(s);
			}
			System.out.println();
		}
	}

	private static List<String> djsk(int[] availble, int[][][] p){
		List<String> ret = new LinkedList<String>();
		System.out.println("testA = " + availble[0] + " " + availble[1] + " " + availble[2]);
		boolean[] flags = new boolean[p.length];
		for(int x = 0; x < p.length; x ++)
			flags[x] = false;
		while(true){
			int j = -1;
			for(int i = 0; i < p.length; i ++){
				System.out.println((p[i][0][0] - p[i][1][0]) + " " + (p[i][0][1] - p[i][1][1]) + " " + (p[i][0][2] - p[i][1][2]));
				if(((p[i][0][0] - p[i][1][0]) <= availble[0]) &&
						((p[i][0][1] - p[i][1][1]) <= availble[1]) &&
						((p[i][0][2] - p[i][1][2]) <= availble[2]) && 
						!flags[i]){
					j = i;
					break;
				}
			}
			if(j >= 0){
				flags[j] = true;
				ret.add("P" + j + "->");
				availble[0] += p[j][1][0];
				availble[1] += p[j][1][1];
				availble[2] += p[j][1][2];
				System.out.println("a = " + availble[0] + " " + availble[1] + " " + availble[2]);
			}else{
				break;
			}
		}
		ret.add("endl;");
		return ret.size() == 1 ? null : ret;
	}
}

